// 简单的API测试脚本
const testAPI = async () => {
  const baseURL = 'http://localhost:3000/api/v1'

  try {
    console.log('🚀 开始测试后端API连接...')

    // 测试验证码API (不需要认证)
    console.log('\n🔐 测试验证码API...')
    const captchaResponse = await fetch(`${baseURL}/auth/captcha`)
    if (captchaResponse.ok) {
      const captcha = await captchaResponse.json()
      console.log('✅ 验证码API响应成功:', captcha)
    } else {
      console.log('❌ 验证码API响应失败:', captchaResponse.status, await captchaResponse.text())
    }

    // 测试登录API (不需要认证)
    console.log('\n👤 测试登录API...')
    const loginResponse = await fetch(`${baseURL}/auth/login`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        username: 'test',
        password: 'test123'
      })
    })
    if (loginResponse.ok) {
      const login = await loginResponse.json()
      console.log('✅ 登录API响应成功:', login)
    } else {
      console.log('❌ 登录API响应失败:', loginResponse.status, await loginResponse.text())
    }

    console.log('\n🎉 API测试完成！')
    console.log('📱 前端地址: http://localhost:9004')
    console.log('🔧 后端地址: http://localhost:3000')

  } catch (error) {
    console.error('❌ API测试失败:', error.message)
  }
}

// 运行测试
testAPI()